<template>
	<view :class="['page',{'iphoneX':isIphoneX}]">  
		<view class="body">
			<template>
				<template v-if="page=='add'||page=='edit'">
					<view style="font-size: 32rpx;font-weight: bold;padding: 20rpx;">供应商基本信息</view>
					<u--form :model="form" ref="uForm" class="form-wrap"> 
						<u-form-item label="供应商名称" labelWidth="180" prop="name" borderBottom="true" class="u-form-item">
							<u-input v-model="form.name" placeholder="输入供应商名称" border="none" />
						</u-form-item> 
						
						<u-form-item label="供应商等级" labelWidth="180" prop="level_name" borderBottom="true" class="u-form-item">
							<u-input type="text" v-model="form.level_name" placeholder="输入供应商等级" border="none" />
						</u-form-item> 
						<u-form-item label="地址" labelWidth="180" prop="address" borderBottom="true" class="u-form-item">
							<u-input type="text" v-model="form.address" placeholder="输入地址" border="none" />
						</u-form-item> 
					</u--form> 
					<view v-for="(item,index) in operations.data" :key="index" class="m-b2">
						<view style="font-size: 32rpx;font-weight: bold;padding: 20rpx;">业务窗口{{index+1}}</view>
						<u--form :model="form" ref="uForm" class="form-wrap"> 						
							<u-form-item label="姓名" labelWidth="180" prop="realname" borderBottom="true" class="u-form-item">
								<u-input v-model="item.realname" placeholder="输入姓名" border="none" />
							</u-form-item> 
							<u-form-item label="职位" labelWidth="180" prop="realname" borderBottom="true" class="u-form-item">
								<u-input v-model="item.job" placeholder="输入职位" border="none" />
							</u-form-item> 
							<u-form-item label="类型" labelWidth="160" prop="pcategoryname" borderBottom="true" class="u-form-item" @click="operations.currentIndex=index;gystypeList.isShow=true">
								<u-input v-model="item.type_name" placeholder="选择类型" disabled disabledColor="#ffffff" border="none" style="pointer-events: none;"/>
								<u-icon	slot="right" name="arrow-right"></u-icon>						
							</u-form-item> 
							<u-form-item label="手机" labelWidth="180" prop="mobile" borderBottom="true" class="u-form-item">
								<u-input type="number" v-model="item.mobile" placeholder="输入手机" border="none" />
							</u-form-item>
							<u-form-item label="传真" labelWidth="180" prop="fax" borderBottom="true" class="u-form-item">
								<u-input type="text" v-model="item.fax" placeholder="输入传真" border="none" />
							</u-form-item>
							<u-form-item label="座机" labelWidth="180" prop="telephone" borderBottom="true" class="u-form-item">
								<u-input type="text" v-model="item.telephone" placeholder="输入座机" border="none" />
							</u-form-item>
							<u-form-item label="邮箱" labelWidth="180" prop="email" borderBottom="true" class="u-form-item">
								<u-input type="text" v-model="item.email" placeholder="输入邮箱" border="none" />
							</u-form-item>						
						</u--form>
					</view>
					<view class="add-btn" style="margin: 20rpx auto;" @click="addoperation">新增对接人</view>
					
					<view style="font-size: 32rpx;font-weight: bold;padding: 20rpx;">供应商信息</view>
					<u--form :model="form" ref="uForm" class="form-wrap">
						<u-form-item label="注册资本" labelWidth="180" prop="capital_social" borderBottom="true" class="u-form-item">
							<u-input v-model="form.capital_social" placeholder="输入注册资本" border="none" >
								<template slot="suffix"> <u--text text="元" size="28"></u--text></template>
							</u-input>
						</u-form-item> 
						<u-form-item label="成立时间" labelWidth="160" prop="formed" borderBottom="true" class="u-form-item" >
							<view class="form-wrap" style="width: 100%;">
								<view class="form-item" style="padding: 0;"> 
									<picker class="form-picker" mode="date" @change="changeDate(1,$event)">
										<view class="picker">
											<view class="select-data">
												<text v-if="form.formed">{{form.formed}}</text>
												<text v-else class="f-grey">选择成立时间</text>
											</view>
											<view class="icon">
												<view class="iconfont f-s34">&#xe8d4;</view>
											</view>						
										</view>	
									</picker> 						
								</view> 
							</view>			
						</u-form-item>
						<u-form-item label="主营产品" labelWidth="180" prop="main_product" borderBottom="true" class="u-form-item">
							<u-input type="text" v-model="form.main_product" placeholder="输入主营产品" border="none" />
						</u-form-item> 
						<u-form-item label="企业法人" labelWidth="180" prop="business_entity" borderBottom="true" class="u-form-item">
							<u-input type="text" v-model="form.business_entity" placeholder="输入企业法人" border="none" />
						</u-form-item>
						<u-form-item label="统一社会信用代码" labelWidth="260" prop="credit_code" borderBottom="true" class="u-form-item">
							<u-input type="text" v-model="form.credit_code" placeholder="输入统一社会信用代码" border="none" />
						</u-form-item> 
						<u-form-item label="公司性质" labelWidth="180" prop="business_nature" borderBottom="true" class="u-form-item">
							<u-input type="text" v-model="form.business_nature" placeholder="输入公司性质" border="none" />
						</u-form-item> 
						<view class="goods-wrap m-b2">
							<view class="hd-title">
								<u--text class="m-t2 m-b2" text="专利证书" size="30" align="left"></u--text>  
							</view>	
							<view class="upload-wrap">
								<u-upload
									width="180"
									height="180" 
									:previewFullImage="true"
									:fileList="form.fileList1"
									@afterRead="afterRead(1,$event)"
									@delete="deletePic(1,$event)"
									name="1"
									multiple
									:maxCount="10"
								></u-upload>
							</view>
							
						</view>
						<view class="goods-wrap m-b2">
							<view class="hd-title">
								<u--text class="m-t2 m-b2" text="相关资质" size="30" align="left"></u--text>  
							</view>	
							<view class="upload-wrap">
								<u-upload
									width="180"
									height="180" 
									:previewFullImage="true"
									:fileList="form.fileList2"
									@afterRead="afterRead(2,$event)"
									@delete="deletePic(2,$event)"
									name="1"
									multiple
									:maxCount="10"
								></u-upload>
							</view> 
						</view>
						<u-form-item label="工厂规模" labelWidth="180" prop="plant_size" borderBottom="true" class="u-form-item">
							<u-input type="text" v-model="form.plant_size" placeholder="输入工厂规模" border="none" />
						</u-form-item>
						<u-form-item label="职工人数" labelWidth="180" prop="workers" borderBottom="true" class="u-form-item">
							<u-input type="text" v-model="form.workers" placeholder="输入职工人数" border="none" >
								<template slot="suffix"> <u--text text="条" size="28"></u--text></template>
							</u-input>
						</u-form-item>
						<u-form-item label="经营范围" labelWidth="180" prop="business_scope" borderBottom="true" class="u-form-item">
							<u-input type="text" v-model="form.business_scope" placeholder="输入经营范围" border="none" />
						</u-form-item>
					</u--form> 
					
					<view style="font-size: 32rpx;font-weight: bold;padding: 20rpx;">供应商生产能力</view>
					<u--form :model="form" ref="uForm" class="form-wrap">
						<u-form-item label="生产线" labelWidth="180" prop="production_line" borderBottom="true" class="u-form-item">
							<u-input v-model="form.production_line" placeholder="输入生产线" border="none" >
								<template slot="suffix"> <u--text text="条" size="28"></u--text></template>
							</u-input>
						</u-form-item> 
						<u-form-item label="技术指标和优势" labelWidth="240" prop="target_superiority" borderBottom="true" class="u-form-item">
							<u-input v-model="form.target_superiority" placeholder="输入技术指标和优势" border="none" />
						</u-form-item> 
						<u-form-item label="主要客户市场" labelWidth="200" prop="client_market" borderBottom="true" class="u-form-item">
							<u-input type="text" v-model="form.client_market" placeholder="输入主要客户市场" border="none" />
						</u-form-item> 
						 
						
						<u-form-item label="原材料产地" labelWidth="180" prop="parts_area" borderBottom="true" class="u-form-item">
							
							<!-- <u-col span="4">
								<u-form-item label="" labelWidth="" prop="province_name" borderBottom="true" class="u-form-item" @click="province.isShow=true">
									<u-input v-model="form.province_name" placeholder="请选择省" disabled disabledColor="#ffffff" border="none" style="pointer-events: none;"/>
									<u-icon	slot="right" name="arrow-right"></u-icon>		
								</u-form-item>  
							</u-col>
							<u-col span="4">
								<u-form-item v-if="form.province_name" label="" labelWidth="" prop="city_name" borderBottom="true" class="u-form-item" @click="city.isShow=true">
									<u-input v-model="form.city_name" placeholder="选择市" disabled disabledColor="#ffffff" border="none" style="pointer-events: none;"/>
									<u-icon	slot="right" name="arrow-right"></u-icon>		
								</u-form-item> 
							</u-col>
							<u-col span="4">
								<u-form-item v-if="form.city_name" label="" labelWidth="" prop="area_name" borderBottom="true" class="u-form-item" @click="area.isShow=true">
									<u-input v-model="form.area_name" placeholder="选择区" disabled disabledColor="#ffffff" border="none" style="pointer-events: none;"/>
									<u-icon	slot="right" name="arrow-right"></u-icon>		
								</u-form-item>
							</u-col>	 -->
							
							<u-input v-model="form.parts_area" placeholder="输入原材料产地" disabledColor="#ffffff" border="none"/> 				
						</u-form-item>
						<u-form-item label="上一年产量" labelWidth="260" prop="prev_output" borderBottom="true" class="u-form-item">
							<u-input type="text" v-model="form.prev_output" placeholder="输入上一年产量" border="none" />
						</u-form-item> 
					</u--form>
					
					<view style="font-size: 32rpx;font-weight: bold;padding: 20rpx;">银行资料</view>
					<u--form :model="form" ref="uForm" class="form-wrap">
						<u-form-item label="账户名称" labelWidth="180" prop="bank_name" borderBottom="true" class="u-form-item">
							<u-input v-model="form.bank_name" placeholder="输入账户名称" border="none" />
						</u-form-item> 
						<u-form-item label="银行账户" labelWidth="180" prop="realname" borderBottom="true" class="u-form-item">
							<u-input v-model="form.bank_account" placeholder="输入银行账户" border="none" />
						</u-form-item> 
						<u-form-item label="开户行名称" labelWidth="180" prop="bank_account_name" borderBottom="true" class="u-form-item">
							<u-input type="text" v-model="form.bank_account_name" placeholder="输入开户行名称" border="none" />
						</u-form-item>  
						<u-form-item label="联行号" labelWidth="260" prop="bank_sister" borderBottom="true" class="u-form-item">
							<u-input type="text" v-model="form.bank_sister" placeholder="输入联行号" border="none" />
						</u-form-item> 
					</u--form>
					
					<view style="font-size: 32rpx;font-weight: bold;padding: 20rpx;">交易条件</view>
					<u--form :model="form" ref="uForm" class="form-wrap">
						<u-form-item label="产品报价" labelWidth="180" prop="offers" borderBottom="true" class="u-form-item">
							<u-input v-model="form.offers" placeholder="输入产品报价" border="none" >
								<template slot="suffix"> <u--text text="元" size="28"></u--text></template>
							</u-input>
						</u-form-item> 
						<u-form-item label="经营类别" labelWidth="180" prop="business_category" borderBottom="true" class="u-form-item">
							<u-input v-model="form.business_category" placeholder="输入经营类别" border="none" />
						</u-form-item> 
						<u-form-item label="发票类型" labelWidth="180" prop="invoice_type" borderBottom="true" class="u-form-item">
							<u-input type="text" v-model="form.invoice_type" placeholder="输入发票类型" border="none" />
						</u-form-item>  
						<u-form-item label="报价有效期" labelWidth="200" prop="price_validity" borderBottom="true" class="u-form-item">
							<view class="form-wrap" style="width: 100%;">
								<view class="form-item" style="padding: 0;"> 
									<picker class="form-picker" mode="date" @change="changeDate(2,$event)">
										<view class="picker">
											<view class="select-data">
												<text v-if="form.price_validity">{{form.price_validity}}</text>
												<text v-else class="f-grey">选择报价有效期</text>
											</view>
											<view class="icon">
												<view class="iconfont f-s34">&#xe8d4;</view>
											</view>						
										</view>	
									</picker> 						
								</view> 
							</view>				
						</u-form-item> 
						<u-form-item label="付款条件" labelWidth="260" prop="terms" borderBottom="true" class="u-form-item">
							<u-input type="text" v-model="form.terms" placeholder="输入付款条件" border="none" />
						</u-form-item> 
						<u-form-item label="税率" labelWidth="260" prop="tax_rate" borderBottom="true" class="u-form-item">
							<u-input type="text" v-model="form.tax_rate" placeholder="输入税率" border="none" >
								<template slot="suffix"> <u--text text="%" size="28"></u--text></template>
							</u-input>
						</u-form-item> 
						<u-form-item label="是否签注保密协议" labelWidth="320" prop="telephone" borderBottom="true" class="u-form-item">
							<u-radio-group iconPlacement="left" activeColor="#0099ff" inactiveColor="#cccccc" v-model="form.is_privary">
								<u-radio class="m-r2" label="是" name="1" size="30" labelSize="30"></u-radio>
								<u-radio label="否" name="0" size="30" labelSize="30"></u-radio>
							</u-radio-group>
						</u-form-item> 
						<u-form-item label="是否签注廉洁协议" labelWidth="320" prop="telephone" borderBottom="true" class="u-form-item">
							<u-radio-group iconPlacement="left" activeColor="#0099ff" inactiveColor="#cccccc"  v-model="form.is_honest">
								<u-radio class="m-r2" label="是" name="1" size="30" labelSize="30"></u-radio>
								<u-radio label="否" name="0" size="30" labelSize="30"></u-radio>
							</u-radio-group>
						</u-form-item> 
						<u-form-item label="是否签注品质保证协议" labelWidth="360" prop="telephone" borderBottom="true" class="u-form-item">
							<u-radio-group iconPlacement="left" activeColor="#0099ff" inactiveColor="#cccccc"  v-model="form.is_quality">
								<u-radio class="m-r2" label="是" name="1" size="30" labelSize="30"></u-radio>
								<u-radio label="否" name="0" size="30" labelSize="30"></u-radio>
							</u-radio-group>
						</u-form-item> 
					</u--form>
					
				</template>
				
				<template v-if="page=='detail'">
					<u--form :model="form" ref="uForm" class="form-wrap"> 
						<u-form-item label="部门" labelWidth="160" prop="pcategoryname" borderBottom="true" class="u-form-item">
							<u-input v-model="form.dep_name" placeholder="选择部门" disabled disabledColor="#ffffff" border="none" style="pointer-events: none;"/> 				
						</u-form-item>
						<u-form-item label="联系人" labelWidth="160" prop="realname" borderBottom="true" class="u-form-item">
							<u-input v-model="form.realname" placeholder="输入联系人" disabled border="none" />
						</u-form-item> 
						
						<u-form-item label="联系电话" labelWidth="160" prop="telephone" borderBottom="true" class="u-form-item">
							<u-input type="number" v-model="form.telephone" disabled placeholder="输入联系电话" border="none" />
						</u-form-item> 
						
						<template v-if="form.dep_id==1||form.dep_id==2">
							
							<u-form-item label="单位名称" labelWidth="160" prop="company" borderBottom="true" class="u-form-item">
								<u-input v-model="form.company" placeholder="输入单位名称" disabled border="none" />
							</u-form-item> 
							<u-form-item label="客户职务" labelWidth="160" prop="job" borderBottom="true" class="u-form-item">
								<u-input v-model="form.job" placeholder="输入客户职务" disabled border="none" />
							</u-form-item> 							
							<u-form-item label="省" labelWidth="160" prop="province_name" borderBottom="true" class="u-form-item">
								<u-input v-model="form.province_name" placeholder="请选择省" disabled disabledColor="#ffffff" border="none" style="pointer-events: none;"/>
								<u-icon	slot="right" name="arrow-right"></u-icon>		
							</u-form-item>  
							<u-form-item v-if="form.province_name" label="市" labelWidth="160" prop="city_name" borderBottom="true" class="u-form-item"> 
								<u-input v-model="form.city_name" placeholder="选择市" disabled disabledColor="#ffffff" border="none" style="pointer-events: none;"/>
								<u-icon	slot="right" name="arrow-right"></u-icon>		
							</u-form-item> 
							<u-form-item v-if="form.city_name" label="区" labelWidth="160" prop="area_name" borderBottom="true" class="u-form-item">
								<u-input v-model="form.area_name" placeholder="选择区" disabled disabledColor="#ffffff" border="none" style="pointer-events: none;"/>
								<u-icon	slot="right" name="arrow-right"></u-icon>		
							</u-form-item> 
							<u-form-item label="地址" labelWidth="160" prop="address" borderBottom="true" class="u-form-item">
								<view class="address-area">
									<view><u--textarea v-model="form.address" disabled placeholder="请输入地址" count ></u--textarea></view>	
								</view> 
							</u-form-item> 
							<u-form-item label="业务关系" labelWidth="160" prop="business" borderBottom="true" class="u-form-item">
							 	<u-input v-model="form.business" placeholder="输入业务关系" disabled border="none" />
							</u-form-item>
							
						</template> 
						<template v-if="form.dep_id==3">
							<u-form-item label="供货商名称" labelWidth="180" prop="company" borderBottom="true" class="u-form-item">
								<u-input v-model="form.company" placeholder="输入供货商名称" disabled border="none" />
							</u-form-item> 
							<u-form-item label="设备名称" labelWidth="160" prop="goods_name" borderBottom="true" class="u-form-item">
								<u-input v-model="form.goods_name" placeholder="输入设备名称" disabled border="none" />
							</u-form-item> 
							<u-form-item label="规格型号" labelWidth="160" prop="spec" borderBottom="true" class="u-form-item">
								<u-input v-model="form.spec" placeholder="输入规格型号" disabled border="none" />
							</u-form-item>
							<u-form-item label="采购单价" labelWidth="160" prop="price" borderBottom="true" class="u-form-item">
								<u-input v-model="form.price" placeholder="输入采购单价" disabled border="none" />
							</u-form-item> 
							<u-form-item label="供货商地址" labelWidth="180" prop="address" borderBottom="true" class="u-form-item">
								<view class="address-area">
									<view><u--textarea v-model="form.address" placeholder="请输入供货商地址" disabled count ></u--textarea></view>	
								</view> 
							</u-form-item> 
						</template>
						<template v-if="form.dep_id==4">
							<u-form-item label="机构名称" labelWidth="160" prop="company" borderBottom="true" class="u-form-item">
								<u-input v-model="form.company" placeholder="输入机构名称" disabled border="none" />
							</u-form-item> 
							<u-form-item label="职务" labelWidth="160" prop="job" borderBottom="true" class="u-form-item">
								<u-input v-model="form.job" placeholder="输入职务" disabled border="none" />
							</u-form-item> 
							<u-form-item label="地址" labelWidth="160" prop="address" borderBottom="true" class="u-form-item">
								<view class="address-area">
									<view><u--textarea v-model="form.address"  disabled placeholder="请输入地址" count ></u--textarea></view>	
								</view> 
							</u-form-item> 
							<u-form-item label="业务关系" labelWidth="160" prop="business" borderBottom="true" class="u-form-item">
							 	<u-input v-model="form.business" placeholder="输入业务关系" disabled border="none" />
							</u-form-item>
						</template>
						<template v-if="form.dep_id==5">
							<u-form-item label="电商平台" labelWidth="160" prop="eplat" borderBottom="true" class="u-form-item">
								<u-input v-model="form.eplat" placeholder="输入电商平台" disabled border="none" />
							</u-form-item> 
							<u-form-item label="具体项目" labelWidth="160" prop="project" borderBottom="true" class="u-form-item">
								<u-input v-model="form.project" placeholder="输入具体项目" disabled border="none" />
							</u-form-item> 
							<u-form-item label="收费标准" labelWidth="160" prop="rates" borderBottom="true" class="u-form-item">
								<u-input v-model="form.rates" placeholder="输入收费标准" disabled border="none" />
							</u-form-item> 
							<u-form-item label="服务单位名称" labelWidth="200" prop="company" borderBottom="true" class="u-form-item">
								<u-input v-model="form.company" placeholder="输入服务单位名称" disabled border="none" />
							</u-form-item> 
							<u-form-item label="联系地址" labelWidth="160" prop="address" borderBottom="true" class="u-form-item">
								<view class="address-area">
									<view><u--textarea v-model="form.address" placeholder="请输入联系地址" disabled count ></u--textarea></view>	
								</view> 
							</u-form-item> 
						</template>
						<template v-if="form.dep_id==6">
							<u-form-item label="具体事项" labelWidth="160" prop="goods_name" borderBottom="true" class="u-form-item">
								<u-input v-model="form.goods_name" placeholder="输入具体事项" disabled border="none" />
							</u-form-item> 
							<u-form-item label="收费标准" labelWidth="160" prop="rates" borderBottom="true" class="u-form-item">
								<u-input v-model="form.rates" placeholder="输入收费标准" disabled border="none" />
							</u-form-item>
							 <u-form-item label="服务单位" labelWidth="160" prop="company" borderBottom="true" class="u-form-item">
							 	<u-input v-model="form.company" placeholder="输入服务单位名称" disabled border="none" />
							 </u-form-item> 
						</template>
						
						
						
						<u-form-item label="备注" labelWidth="160" prop="remark" borderBottom="true" class="u-form-item">
							<view class="address-area" >
								<view><u--textarea v-model="form.remark" placeholder="请输入备注" disabled count ></u--textarea></view>	
							</view> 
						</u-form-item>  
						
						  
					</u--form>
					 
					 
				</template>
			</template>
			
			 
			 
			
			<u-picker :show="gystypeList.isShow" :columns="gystypeList.data" keyName="name" :defaultIndex="gystypeList.defaultIndex" itemHeight="90" :closeOnClickOverlay="true" @cancel="gystypeList.isShow=false" @confirm="changegystypeList" @close="gystypeList.isShow=false"></u-picker>
			
			<u-picker :show="deplist.isShow" :columns="deplist.data" keyName="name" :defaultIndex="deplist.defaultIndex" itemHeight="90" :closeOnClickOverlay="true" @cancel="deplist.isShow=false" @confirm="changedeplist" @close="deplist.isShow=false"></u-picker>
			
			<u-picker :show="province.isShow" :columns="province.data" keyName="name" :defaultIndex="province.defaultIndex" itemHeight="90" :closeOnClickOverlay="true" @cancel="province.isShow=false" @confirm="changeprovince" @close="province.isShow=false"></u-picker>
			
			<u-picker :show="city.isShow" :columns="city.data" keyName="name" :defaultIndex="city.defaultIndex" itemHeight="90" :closeOnClickOverlay="true" @cancel="city.isShow=false" @confirm="changecity" @close="city.isShow=false"></u-picker>
			
			<u-picker :show="area.isShow" :columns="area.data" keyName="name" :defaultIndex="area.defaultIndex" itemHeight="90" :closeOnClickOverlay="true" @cancel="area.isShow=false" @confirm="changearea" @close="area.isShow=false"></u-picker>
			
			<u-picker :show="unit.isShow" :columns="unit.data" keyName="uname" :defaultIndex="unit.defaultIndex" itemHeight="90" :closeOnClickOverlay="true" @cancel="unit.isShow=false" @confirm="changeunit" @close="unit.isShow=false"></u-picker>
			
			<view v-if="unit.isAdd" style="position: absolute;z-index: 10078;">
				<u-picker :show="unit.isAdd" :columns="unit.data" keyName="uname" :defaultIndex="unit.adddefaultIndex" itemHeight="90" :closeOnClickOverlay="true" @cancel="unit.isAdd=false" @confirm="changeaddunit" @close="unit.isAdd=false"></u-picker>
			</view>
			
			<u-popup :show="partslist.isShow" mode="right" class="popup-height">
				<view class="partslist-popup">
					<u--text class="hd" text="选择材料配置" size="30" :bold="true" align="center"></u--text>
					<view class="select-wrap">
						<view class="scroll-view">
							<u-button v-if="item.status==1"  class="item" :type="item.checked?'primary':'info'" :plain="true" size="small" :text="item.pname" v-for="(item,index) in partslist.data[0]" :key="index" @click="selectpartslist(index)"></u-button>
						</view> 
					</view>
					<view class="btn-wrap">
						<u-button text="取消" type="warning" size="small" class="btn" @click="partslist.isShow=false"></u-button>
						<u-button text="确定" type="primary" size="small" class="btn" @click="partslist.isShow=false"></u-button>
					</view>
				</view>
			</u-popup>	
			
			<u-popup :show="minunits.isShow" mode="right" :customStyle="popupCustomStyle" :safeAreaInsetBottom="true" :safeAreaInsetTop="true">
				<view class="partslist-popup">
					<u--text class="hd" text="选择子集单位" size="30" :bold="true" align="center"></u--text>
					<view class="select-wrap" :style="'height:'+ 'calc(100% - '+(100+systemInfo.statusBarHeight)+'px)'">
						<view class="scroll-view">
							<view class="item">
								<u-button :type="item.checked?'primary':'info'" :plain="true" size="small" :text="item.name" v-for="(item,index) in minunits.data" :key="index" @click="selectminunit(index)"></u-button>						  	     <u--input placeholder="请输入数量"  border="surround" ></u--input>
							</view>
							
						</view>
					</view>
					<view class="btn-wrap">
						<u-button text="取消" type="warning" size="small" class="btn" @click="minunits.isShow=false" ></u-button>
						<u-button text="确定" type="primary" size="small" class="btn" @click="minunits.isShow=false"></u-button>
					</view>
				</view>
			</u-popup>			 
					
			<u-modal :show="isAddUnit" title="添加单位" showCancelButton confirmText="确认添加" cancelText="暂不添加" @cancel="hideaddUnit" @confirm="addUnit">
				<view class="slot-content">
					<u--form :model="form" ref="uForm" class="form-wrap"> 
						<u-form-item label="选择级别" labelWidth="160" prop="add_unit_name" borderBottom="true" class="u-form-item"  @click="unit.isAdd=true">
							<u-input v-model="form.add_unit_name" disabled disabledColor="#ffffff" border="none" placeholder="选择级别" />
							<u-icon	slot="right" name="arrow-right"></u-icon>	
						</u-form-item>  
						<u-form-item label="单位名称" labelWidth="160" prop="uname" borderBottom="true" class="u-form-item">
							<u-input v-model="form.uname" placeholder="输入单位名称" border="none" />
						</u-form-item>
						<u-form-item v-if="form.add_unit_id!=0" label="比例" labelWidth="160" prop="pname" borderBottom="true" class="u-form-item">
							<u-input v-model="form.unit_count" placeholder="输入比例" border="none" />
							<u--text :text="form.add_unit_name" size="28"  align="center"></u--text>
						</u-form-item>
					</u--form> 
				</view>
			</u-modal>
			
			<u-modal :show="isAddtype" title="添加类别" showCancelButton confirmText="确认添加" cancelText="暂不添加" @cancel="isAddtype=false" @confirm="addType">
				<view class="slot-content">
					<u--form :model="form" ref="uForm" class="form-wrap"> 
						<u-form-item label="类别名称" labelWidth="160" prop="addtypeanme" borderBottom="true" class="u-form-item">
							<u-input v-model="form.addtypeanme" placeholder="输入类别名称" border="none" />
						</u-form-item> 						 
					</u--form> 
				</view>
			</u-modal>
			 
		</view>  
		
		<!-- <view class="add-btn" @click="add">{{提交}}</view> -->
		<c-footer> 
			<view v-if="page=='add'" slot="content" class="add-btn" @click="add">提交</view>
			<view v-if="page=='edit'" slot="content" class="add-btn" @click="add">保存编辑</view>
			
		</c-footer>
	</view>
</template>

<script>
	import {uploadToServe} from '@/common/util.js'
	import {IMG_PATH} from '../../config.js'
	export default {
		data() {
			return {
				id:'',
				isLogin:true, 
				isIphoneX:getApp().globalData.isIphoneX,
				isAddtype:false,
				isAddUnit:false,
				systemInfo:getApp().globalData.systemInfo,
				isShowSearch:false,
				type:'', 
				page:'',
				list:[],
				operations:{ 
					num:0,
					data:[{
						realname:"",
						job:"",
						type:"",
						type_name:'',
						mobile:"",
						telephone:"",
						fax:"",
						email:"" 
					}], 
					currentIndex:0
				},				
				form: {
					id:'',
					name:'',
					level_name:'',
					address:'',
					capital_social:'',
					business_entity:'',
					formed:'',
					credit_code:'',
					main_product:'',
					business_nature:'',
					workers:'',
					plant_size:'',
					business_scope:'',
					production_line:'',
					parts_area:'',
					target_superiority:'',
					prev_output:'',
					client_market:'',
					bank_name:'',
					bank_account_name:'',
					bank_account:'',
					bank_sister:'',
					offers:'',
					price_validity:'',
					business_category:'',
					terms:'',
					invoice_type:'',
					tax_rate:'',
					is_privary:"",
					is_honest:"",
					is_quality:"",
					f_ids:'',
					operation:[],
					fileList1:[],
					fileList2:[],
					province_id:'',
					province_name:'',
					city_id:'',
					city_name:'',
					area_id:'',
					area_name:'',
					
					pcategoryid:'',
					pcategoryname:'',
					pname:'',
					partslist:[],
					partslistname:[],
					partstype:'',
					partstypename:'',
					unit_id:'',
					unit_name:'',
					add_unit_name:'',
					add_unit_id:'',
					number:'0',
					min_unit:[], 
					min_unit_name:[],
					status:1,
					addtypeanme:'', 
					uname:'',
					unit_count:''
				},
				gystypeList:{
					isShow:false,
					data:[[]],
					defaultIndex:[]
				},
				deplist:{
					isShow:false,
					data:[[]],
					defaultIndex:[]
				},
				province:{
					isShow:false,
					data:[[]],
					defaultIndex:[]
				},
				city:{
					isShow:false,
					data:[[]],
					defaultIndex:[]
				},
				area:{
					isShow:false,
					data:[[]],
					defaultIndex:[]
				},
				
				
				pcategory:{
					isShow:false,
					data:[[]],
					defaultIndex:[]
				},
				partstype:{
					isShow:false,
					data:[[]],
					defaultIndex:[]
				},
				unit:{
					isAdd:false,
					isShow:false,
					data:[],
					defaultIndex:[],
					adddefaultIndex:[],
				},
				
				partslist:{
					isShow:false,
					data:[[]],
					defaultIndex:[]
				},
				minunits:{
					isShow:false,
					data:[],
					defaultIndex:[]
				},				 
				hp_count:[], 
				popupCustomStyle:{
					width:'100%'
				},
				selectParts:[],
				selectPartstype:[] ,
				isStop:true
			}
		},
		async onLoad(params) { 
			this.type=params.type;
			this.page=params.page; 
			this.gystypeList.data[0]=this.$mock_data.gystypeList;
		 
			let title=''; 
			if(this.page=='add'){
				title='新增供应商'; 
				this.getArea(0,'province')
			}
			if(this.page=='edit'){
				this.form.id=params.id;
				title='编辑供应商';  
				await this.getArea(0,'province');				
				let detail=await this.getspsupplierinfo();	
					
				this.form={
					id:detail.id,
					name:detail.name,
					level_name:detail.level_name,
					address:detail.address,
					capital_social:detail.capital_social,
					business_entity:detail.business_entity,
					formed:detail.formed,
					credit_code:detail.credit_code,
					main_product:detail.main_product,
					business_nature:detail.business_nature,
					workers:detail.workers,
					plant_size:detail.plant_size,
					business_scope:detail.business_scope,
					production_line:detail.production_line,
					parts_area:detail.name,
					target_superiority:detail.target_superiority,
					prev_output:detail.prev_output,
					client_market:detail.client_market,
					bank_name:detail.bank_name,
					bank_account_name:detail.bank_account_name,
					bank_account:detail.bank_account,
					bank_sister:detail.bank_sister,
					offers:detail.offers,
					price_validity:detail.price_validity,
					business_category:detail.business_category,
					terms:detail.terms,
					invoice_type:detail.invoice_type,
					tax_rate:detail.tax_rate,
					is_privary:detail.is_privary,
					is_honest:detail.is_honest,
					is_quality:detail.is_quality, 
					fileList1:[],
					fileList2:[]
				}  
				// this.$set(this.operations.data,0,detail.operation);
				detail.operation.forEach(i=>{
					this.gystypeList.data[0].forEach(j=>{
						if(i.type==j.value){
							i.type_name=j.name;
						}
					})
				})
				this.operations.data=detail.operation;
				this.operations.num=detail.operation.length; 
				detail.files.forEach(i=>{
					i.url=`${IMG_PATH}${i.file_path}/${i.file_name}`;
					if(i.type==1){						
						this.form.fileList1.push(i);
					}
					if(i.type==2){
						this.form.fileList2.push(i);
					}
				})
				
			}
			if(this.page=='detail'){
				title='供应商详情';
				await this.getcrmcustomerdeplist();
				await this.getArea(0,'province')
				let detail=JSON.parse(params.detail);	
				console.log('detail',detail)
				this.form={
					id:detail.id,
					dep_id:detail.dep_id, 
					dep_name:'',
					realname:detail.realname,
					company:detail.company,
					job:detail.job,
					telephone:detail.telephone,
					province_id:detail.province_id,
					province_name:'',
					city_id:detail.city_id,
					city_name:'',
					area_id:detail.area_id,
					area_name:'',
					address:detail.address,
					business:detail.business,
					remark:detail.remark,
					goods_name:detail.goods_name,
					spec:detail.spec,
					price:detail.price,
					eplat:detail.eplat,
					project:detail.project,
					rates:detail.rates,
				} 
				this.deplist.data[0].forEach(i=>{
					if(i.id==detail.dep_id){
						this.form.dep_name=i.name;
					}
				})
				this.province.data[0].forEach(async i=>{
					if(i.id==detail.province_id){
						this.form.province_name=i.name; 
					}
				})
				await this.getArea(detail.province_id,'city'); 
				this.city.data[0].forEach(i=>{
					if(i.id==detail.city_id){
						this.form.city_name=i.name;						
					}
				})
				await this.getArea(detail.city_id,'area');
				this.area.data[0].forEach(i=>{
					if(i.id==detail.area_id){
						this.form.area_name=i.name;						
					}
				})
			}
			uni.setNavigationBarTitle({
				title:title
			})				
			
			
			 
		},
		onShow() {
			
		}, 
		methods: {
			
			changeDate(type,e){ 
				if(type==1){
					this.form.formed=e.target.value;
				}
				if(type==2){
					this.form.price_validity=e.target.value;
				}
			},
			// 删除图片
			deletePic(type,event) {
				if(type==1){
					this.form.fileList1.splice(event.index, 1)
				}
				if(type==2){
					this.form.fileList2.splice(event.index, 1)
				} 
			},
			
			// 新增图片
			async afterRead(type,event) {
				// 当设置 multiple 为 true 时, file 为数组格式，否则为对象格式
				let lists = [].concat(event.file);
				let api_url='/api/spfile/uploadfile';
				let fileListLen = 0; 
				if(type==1){ 
					fileListLen = this.form.fileList1.length;
					lists.map((item) => {
						this.form.fileList1.push({
							...item,
							status: 'uploading',
							message: '上传中'
						}) 
					})
				}	
				if(type==2){ 
					fileListLen = this.form.fileList2.length;
					lists.map((item) => {
						this.form.fileList2.push({
							...item,
							status: 'uploading',
							message: '上传中'
						}) 
					})
				}
				
				for (let i = 0; i < lists.length; i++) { 
					uploadToServe({
						url: api_url,
						filePath: lists[i].url,
						name: 'fileinput',
						formData: {
							type:type, 
						}
					}).then((res)=>{ 
						if(type==1){
							let item = this.form.fileList1[fileListLen];
							this.form.fileList1.splice(fileListLen, 1, Object.assign(item, {
								status: 'success',
								message: '',
								url: `${IMG_PATH}${res.data.file_path}/${res.data.file_name}`,
								name:res.data.file_name,
								id:res.data.id
							}))
						}	
						if(type==2){
							let item = this.form.fileList2[fileListLen];
							this.form.fileList2.splice(fileListLen, 1, Object.assign(item, {
								status: 'success',
								message: '',
								url: `${IMG_PATH}${res.data.file_path}/${res.data.file_name}`,
								name:res.data.file_name,
								id:res.data.id
							}))
						}									
						fileListLen++ 
					}) 
				}
			}, 
			
			 
			
			async addoperation(){
				this.operations.num+=1; 
				let data={
					realname:"",
					job:"",
					type:"",
					mobile:"",
					telephone:"",
					fax:"",
					email:"" 
				};
				this.$set(this.operations.data,this.operations.num,data); 
			},
			
			async getspsupplierinfo(){
				let res=await this.$api.user_api.spsupplierinfo({
					id:this.form.id
				});  
				if(res.data.code==200){    
					return res.data.data; 
				} 
			}, 
			async getArea(pid,level){
				let res=await this.$api.user_api.regionnext({
					pid:pid
				});     
				if(res.data.code==200){   
					if(pid==0&&level=='province'){
						this.$set(this.province.data,0,res.data.data); 
					}
					if(level=='city'){
						this.$set(this.city.data,0,res.data.data); 
					}
					if(level=='area'){
						this.$set(this.area.data,0,res.data.data); 
					}
					
				} 
			}, 
			changegystypeList(e){ 
				console.log(e)				
				this.operations.data[this.operations.currentIndex].type_name=e.value[0].name;
				this.operations.data[this.operations.currentIndex].type=e.value[0].value;
				this.gystypeList.isShow=false; 				
			},
			changeprovince(e){
				this.province.defaultIndex=e.indexs;
				this.form.province_id=e.value[0].id;
				this.form.province_name=e.value[0].name;
				this.form.city_id='';
				this.form.city_name='';
				this.city.defaultIndex=[];
				this.form.area_id='';
				this.form.area_name='';
				this.area.defaultIndex=[]; 
				this.getArea(this.form.province_id,'city');
				this.province.isShow=false;		
			},
			changecity(e){
				this.city.defaultIndex=e.indexs;
				this.form.city_id=e.value[0].id;
				this.form.city_name=e.value[0].name;
				this.form.area_id='';
				this.form.area_name='';  
				this.area.defaultIndex=[];
				this.getArea(this.form.city_id,'area');
				this.city.isShow=false;		
			},
			changearea(e){
				this.area.defaultIndex=e.indexs;
				this.form.area_id=e.value[0].id;
				this.form.area_name=e.value[0].name;  
				this.area.isShow=false;		
			},
			
			changedeplist(e){
				this.deplist.defaultIndex=e.indexs; 
				this.deplist.isShow=false;	
				this.form={
					id:'',
					dep_id:e.value[0].id,
					dep_name:e.value[0].name,
					realname:'',
					company:'',
					job:'',
					telephone:'',
					province_id:'',
					province_name:'',
					city_id:'',
					city_name:'',
					area_id:'',
					area_name:'',
					address:'',
					business:'',
					remark:'',
					goods_name:'',
					spec:'',
					price:'',
					eplat:'',
					project:'',
					rates:''
				}
			},
			
			selectparts(){ 
				uni.navigateTo({
					url:`/package_kucun/list-select/list-select?page=parts&tname=${this.form.partstypename}&tid=${this.form.partstype}&current=${JSON.stringify(this.form.partslist)}`
				})
			},
			hideaddUnit(){
				this.isAddUnit=false;
				this.unit.data[0].splice(0,1);
			},
			addNewUnit(){ 
				this.isAddUnit=true;
				this.unit.data[0].unshift({
					id:0,
					uname:'最小单位'
				})
				this.form.add_unit_id=this.unit.data[0][0].id;
				this.form.add_unit_name=this.unit.data[0][0].uname;
			},
			async addUnit(){
				let {add_unit_id,uname,	unit_count}=this.form;
				if(uname==''){
					this.$showToast({
						title:'请输入单位名称',
						duration:1000,
					})
					return
				}
				if(add_unit_id!=0&&unit_count==''){
					this.$showToast({
						title:'请输入单位比例',
						duration:1000,
					})
					return
				}
				let res=await this.$api.user_api.partsaddunit({
					pid:add_unit_id,
					uname,
					unit_count,
					status:1
				}) 
				if(res.data.code==200){
					this.$showToast({
						title:res.data.msg,
						duration:1000,
					})
					this.isAddUnit=false;
					this.form.uname='';
					this.form.unit_count='';
					this.unit.data[0].splice(0,1);
					this.unitlistsel(); 
				}
			},
			
			async addType(){
				if(this.form.addtypeanme==''){
					this.$showToast({
						title:'请输入类别名称',
						duration:1000,
					})
					return
				}
				let res=await this.$api.user_api.partsaddtype({
					cname:this.form.addtypeanme,
					status:1
				}) 
				if(res.data.code==200){
					this.$showToast({
						title:res.data.msg,
						duration:1000,
					})
					this.isAddtype=false;
					this.form.addtypeanme='';
					this.partstypes();
				}
			},
			
			selectminunit(idx){
				let id=this.minunits.data[idx].id,
					name=this.minunits.data[idx].name;
				if(this.form.min_unit.indexOf(id)==-1){ 
					this.form.min_unit.push(id);
					this.form.min_unit_name.push(name);
					this.minunits.data[idx].checked=true;
				}else{ 
					let index=this.form.min_unit.indexOf(id);
					this.form.min_unit.splice(index,1);
					this.form.min_unit_name.splice(index,1);
					this.minunits.data[idx].checked=false;
				}
			},
			
			async producttypeinfo(){
				let res=await this.$api.user_api.producttypelistone({
					id:this.id
				})    
				if(res.data.code==200){
					this.form.pname=res.data.data.pname;
					this.form.pcategoryid=res.data.data.pcategoryid;
					this.form.pcategoryname=res.data.data.pcategory;
					this.hp_count=res.data.data.hp_count;
					 
					res.data.data.partslist.forEach(i=>{
						let item={};
						item.parts_type_name=i.type_name;
						item.pname=i.parts_name;
						item.num=i.num;
						item.uname=i.uname;  
						this.form.partslistname.push(item);
					})
					 
					res.data.data.unit_id=res.data.data.unit_id.split(','); 
					res.data.data.unit_id.forEach((item,index)=>{
						this.unit.data[0].forEach(async (subitem,subindex)=>{
							if(item==subitem.id){
								this.form.unit_id=subitem.id;
								this.form.unit_name=subitem.uname;
								this.unit.defaultIndex=[subindex];
								
							}							
						}) 
					}) 
					await this.subunitlistsel(this.form.unit_id); 
					
					res.data.data.unit_id.forEach((item,index)=>{
						this.minunits.data.forEach(subitem=>{
							if(item==subitem.id){
								this.form.min_unit.push(subitem.id);
								this.form.min_unit_name.push(subitem.name); 
								subitem.checked=true;
							}							
						}) 
					}) 
					 
					if(res.data.data.partstype){
						this.form.partstype=res.data.data.partstype;
						await this.getpartslist(this.form.partstype);
						this.partstype.data[0].forEach((item,index)=>{
							if(item.id==res.data.data.partstype){
								this.form.partstypename=item.cname;
								this.partstype.defaultIndex=[index]; 
							}
						}) 
					}
					
					this.form.partslist=res.data.data.partslist.split(',');	 
					this.form.partslist.forEach(item=>{
						this.partslist.data[0].forEach(subitem=>{
							if(item==subitem.id){
								this.form.partslistname.push(subitem.pname);
								subitem.checked=true;
							}
						})						
					}) 					 
				}
			},
			
			async partspartinfo(){
				let res=await this.$api.user_api.partspartinfo({
					id:this.id
				})     
				if(res.data.code==200){
					this.form.pname=res.data.pdata.pname;
					this.form.number=res.data.pdata.number;  
					this.form.unit_id=res.data.pdata.min_unit;  
					this.unit.data[0].forEach((subitem,subindex)=>{
						if(this.form.unit_id==subitem.id){
							this.form.unit_id=subitem.id;
							this.form.unit_name=subitem.uname;
							this.unit.defaultIndex=[subindex];
							
						}							
					})  					 
					this.form.partstype=res.data.pdata.typeid; 
					this.partstype.data[0].forEach((item,index)=>{
						if(item.id==this.form.partstype){
							this.form.partstypename=item.cname;
							this.partstype.defaultIndex=[index]; 
						}
					})   					 
				}
			},
			
			async add(){  
				let {id,name,level_name,address,capital_social,business_entity,formed,credit_code,main_product,business_nature,workers,plant_size,business_scope,production_line,parts_area,
					target_superiority,prev_output,client_market,bank_name,bank_account_name,bank_account,bank_sister,offers,price_validity,business_category,terms,invoice_type,tax_rate,is_privary,
					is_honest,is_quality,f_ids,operation,fileList1,fileList2,province_id,province_name,city_id,city_name,area_id,area_name}=this.form; 
				
				let params={name,level_name,address,capital_social,business_entity,formed,credit_code,main_product,business_nature,workers,plant_size,business_scope,production_line,parts_area,
						target_superiority,prev_output,client_market,bank_name,bank_account_name,bank_account,bank_sister,offers,price_validity,business_category,terms,invoice_type,tax_rate,is_privary,
						is_honest,is_quality
				};
				if(name==''){
					this.$showToast({
						title:'请输入供应商名称',
						duration:1000,
					})
					return
				}
				if(address==''){
					this.$showToast({
						title:'请输入地址',
						duration:1000,
					})
					return
				} 
				if(capital_social==''){
					this.$showToast({
						title:'请输入注册资本',
						duration:1000,
					})
					return
				} 
				if(main_product==''){
					this.$showToast({
						title:'请输入主营产品',
						duration:1000,
					})
					return
				} 
				if(business_entity==''){
					this.$showToast({
						title:'请输入企业法人',
						duration:1000,
					})
					return
				}
				if(credit_code==''){
					this.$showToast({
						title:'请输入统一社会信用代码',
						duration:1000,
					})
					return
				}
				if(fileList1.length==0){
					this.$showToast({
						title:'请上传专利正式',
						duration:1000,
					})
					return
				}
				if(bank_name==''){
					this.$showToast({
						title:'请输入账户名称',
						duration:1000,
					})
					return
				}
				if(bank_account==''){
					this.$showToast({
						title:'请输入银行账号',
						duration:1000,
					})
					return
				}
				if(bank_account_name==''){
					this.$showToast({
						title:'请输入开户行名称',
						duration:1000,
					})
					return
				}
				if(bank_sister==''){
					this.$showToast({
						title:'请输入联行号',
						duration:1000,
					})
					return
				}
				if(business_category==''){
					this.$showToast({
						title:'请输入经营类别',
						duration:1000,
					})
					return
				}
				if(invoice_type==''){
					this.$showToast({
						title:'请输入发票类型',
						duration:1000,
					})
					return
				}
				if(terms==''){
					this.$showToast({
						title:'请输入付款条件',
						duration:1000,
					})
					return
				}
				if(tax_rate==''){
					this.$showToast({
						title:'请输入税率',
						duration:1000,
					})
					return
				}
				for(let i=0;i<this.operations.data.length;i++){ 
					if(this.operations.data[i].realname==''||this.operations.data[i].job==''||this.operations.data[i].type==''||this.operations.data[i].mobile==''){
						this.$showToast({
							title:'请填写完整业务窗口' 
						})
						return
					}  
				}
				
				if(id){
					params.id=id;
				}
				params.parts_area=province_name+city_name+area_name; 
				params.operation=JSON.stringify(this.operations.data);
				let ids=[];
				fileList1.forEach(i=>{
					ids.push(i.id)
				})
				fileList2.forEach(i=>{
					ids.push(i.id)
				})
				params.f_ids=ids.join(',');
				console.log(params) 
				let res={};
				if(this.isStop){
					this.isStop=false
					if(this.page=='add'){
						res=await this.$api.user_api.spsupplieradd(params) 
					} 
					
					if(this.page=='edit'){
						res=await this.$api.user_api.spsupplieredit(params) 
					}  
				}
				 
				if(res.data.code==200){
					this.isStop=true;
					this.$showToast({
						icon:'success',
						title:res.data.msg,
						duration:1000,
					})
					this.$store.commit('gys_list') 
					setTimeout(()=>{
						uni.navigateBack({
							delta:1
						})
					},300)						
				}else{
					this.isStop=true;
					this.$showToast({
						icon:'none',
						title:res.data.msg,
						duration:1000,
					})
				}
			},
			
			delpartslist(name){ 
				this.partslist.data[0].forEach((item,index)=>{
					if(name==item.pname){
						item.checked=false; 
					}
				})
				let idx=this.form.partslistname.indexOf(name);
				this.form.partslistname.splice(idx,1);
				this.form.partslist.splice(idx,1);				
			},
			
			selectpartslist(idx){ 
				let id=this.partslist.data[0][idx].id,
					pname=this.partslist.data[0][idx].pname;
				if(this.form.partslist.indexOf(id)==-1){ 
					this.form.partslist.push(id);
					this.form.partslistname.push(pname);
					this.partslist.data[0][idx].checked=true;
				}else{ 
					let index=this.form.partslist.indexOf(id);
					this.form.partslist.splice(index,1);
					this.form.partslistname.splice(index,1);
					this.partslist.data[0][idx].checked=false;
				}
				
			},
			
			changepartslist(e){ 
				this.partslist.defaultIndex=e.indexs;
				this.form.partslist=e.value[0].id;
				this.form.partslistname=e.value[0].pname;
				this.partslist.isShow=false;				
			},
			
			changepartstype(e){  
				this.partstype.defaultIndex=e.indexs;
				this.form.partstype=e.value[0].id;
				this.form.partstypename=e.value[0].cname;
				this.partstype.isShow=false;
				// this.form.partslist=[];
				// this.form.partslistname=[];
				this.getpartslist(this.form.partstype);
			},
			
			changeunit(e){ 
				this.unit.defaultIndex=e.indexs;
				this.form.unit_id=e.value[0].id;
				this.form.unit_name=e.value[0].uname;
				this.form.min_unit_name=[];
				this.form.min_unit=[];
				this.unit.isShow=false;
				this.subunitlistsel(this.form.unit_id);
			},
			
			changeaddunit(e){
				this.unit.adddefaultIndex=e.indexs;
				this.form.add_unit_id=e.value[0].id;
				this.form.add_unit_name=e.value[0].uname;
				this.unit.isAdd=false;
				this.form.min_unit=[];
				this.form.min_unit_name=[];
			},
			 
			changepcategory(e){ 
				this.pcategory.defaultIndex=e.indexs;
				this.form.pcategoryid=e.value[0].id;
				this.form.pcategoryname=e.value[0].name;
				this.pcategory.isShow=false;
			},
			
			async productcategorylist(){
				let res=await this.$api.user_api.productcategorylist();   
				if(res.data.code==200){  
					this.$set(this.pcategory.data,0,res.data.data); 
					this.pcategory.defaultIndex=[0];
					this.form.pcategoryid=res.data.data[0].id;
					this.form.pcategoryname=res.data.data[0].name; 
				}
			}, 
			
			async partstypes(){
				let res=await this.$api.user_api.partstypes({
					status:1
				});   
				if(res.data.code==200){  
					this.$set(this.partstype.data,0,res.data.data); 
					this.partstype.defaultIndex=[0];
					this.form.partstype=res.data.data[0].id;
					this.form.partstypename=res.data.data[0].cname;
					this.getpartslist(this.form.partstype); 
				}
			},
			
			async unitlistsel(){
				let res=await this.$api.user_api.unitlistsel({
					pid:0
				});      
				if(res.data.code==200){ 
					
					this.$set(this.unit.data,0,res.data.data);
					this.unit.defaultIndex=[0];
					this.unit.adddefaultIndex=[0];
					this.form.unit_id=res.data.data[0].id;
					this.form.unit_name=res.data.data[0].uname;	
					this.form.add_unit_name=res.data.data[0].uname;	
					this.form.add_unit_id=res.data.data[0].id;	
					this.subunitlistsel(this.form.unit_id)
				}
			}, 
			
			async subunitlistsel(pid){
				let res=await this.$api.user_api.unitlistsel({
					pid:pid
				});     
				if(res.data.code==200){  					  
					res.data.data.forEach(item=>{
						item.name=item.unit_count+item.uname;
						item.checked=false;
					})
					this.minunits.data=res.data.data;
					 
				}
			},
			
			async getpartslist(tid){
				let res=await this.$api.user_api.partslist({
					typeid:tid,
					is_page:''
				}); 				
				if(res.data.code==200){  
					res.data.data.list.forEach(item=>{
						item.checked=false;
					})
					this.$set(this.partslist.data,0,res.data.data.list);   
				} 
			},
			
			  
		},
		computed:{
			list_update(){
				return this.$store.state.caigou_msg_list;
			},
			parts_select(){
				return this.$store.state.parts_select;
			}
			
		},
		watch:{
			parts_select(newer,older){  
				if(newer!=older){
					let index=this.selectParts.findIndex(i=>i.parts_type === newer.parts_type); 
					if(index>=0){
						this.selectParts.splice(index,1,newer)
					}else{
						this.selectParts.push(newer)
					}
					
					this.form.partslist=[];
					this.form.partslistname=[];
					this.selectPartstype=[];
					this.selectParts.forEach(i=>{	
						this.selectPartstype.push(i.parts_type);
						if(i.data.length>0){
							i.data.forEach(j=>{
								let item={};
								item.parts_id=j.id;
								item.parts_type=j.parts_type; 
								item.num=j.num;
								this.form.partslist.push(item);
								this.form.partslistname.push(j);
							}) 
						}	 
					}) 
				} 
			} 
		}
	}
</script>

<style lang="less" >
	.form-wrap{
		padding:0 20rpx; 
		.row-2{
			display: flex;
			justify-content: space-between;
			align-items: center;
		}
	}
	.address-area{
		width: 100%;
	}
	.slot-content{
		.hd{
			padding: 30rpx 0 10rpx;
			font-size: 30rpx;
		}
	}
	.popup-form-wrap{
		padding:20rpx;
		border-radius: 15rpx;		 
	}
	.select-pz-wrap{  
		flex-grow: 2;
		.item{
			flex-grow: 2;
			display: flex; 
			align-items: center;
			margin:0 20rpx 20rpx 0;
			font-size: 30rpx;
			.del-icon{ 
			}
		}
	}
	.add-btn{
		height: 36px;
		line-height: 36px;
		width: 96%;
		margin: 5px auto;
		background: #09f;
		border-radius: 8rpx;
		color: #fff;
		font-size: 30rpx;
		text-align: center;
	}  
	.partslist-popup{  
		position: relative; 
		height: 100%;  
		padding: 0 40rpx; 
		.hd{  
			height: 40px; 
		}
		.select-wrap{  
			height:80%;
			flex-grow: 2; 
			overflow: hidden; 
			background: #f5f5f5;
			.scroll-view{
				height: 100%;
				overflow-y: auto; 
			}
			.item{ 
				margin-bottom: 20rpx;
			}
		}
		.btn-wrap{  
			height: 40px;
			margin: 20rpx 0;
			.btn{
				margin: 0 30rpx;
			}
		}
	}
</style>
